import os, django
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api_automation_test.settings")
django.setup()
# sys.path.append('D:\\项目\\龙盈智达\\接口自动化\\本地仓库\\DjangoAPI\\backend')


from requests import request

from backend.api.getResult import getResult, Lyzd_RunMsg
from backend.serializers import Lyzd_RunMsgSerializer

def runScript():

    content = {
        "progect_id": 1,
        "environment_id": 1,
        "interface_action": ['1'],
        "execute": "0"
    }
    msg = getResult.get(request, content)

    """查询最新运行结果"""

    maxid_msg_data = Lyzd_RunMsg.objects.latest()

    maxid_msg_data.id

    msg_data = Lyzd_RunMsg.objects.filter(id=maxid_msg_data.id)

    serialize = Lyzd_RunMsgSerializer(msg_data, many=True)
    #执行结果
    runResult = eval(serialize.data[0]['msg'])
    sum=str(runResult['共执行接口数量'])
    success=str(runResult['执行成功数量'])
    fial=str(runResult['执行失败数量'])

    returnStdout = "共执行接口数量"+sum+"个,执行成功的数量"+success+"个,执行失败的数量"+fial+"个"
    return returnStdout
